package com.zhoujian.Observer.weather;

import java.util.ArrayList;
import java.util.List;

public class WeatherStation implements Subject{
    //气温
    private float temperature;

    //应该持有多个观察者
    private List<Observer> observers = new ArrayList<>();
    public void changeTemperature(float newTemperature){
        this.temperature = newTemperature;
        notifyObservers();
    }

    @Override
    public void registerObserver(Observer observer) {
        observers.add(observer);
    }

    @Override
    public void removeObserver(Observer observer) {
        observers.remove(observer);
    }

    @Override
    public void notifyObservers() {

    }


    @Override
    public void notifyObservers(float newTemperature) {
        for (Observer observer : observers) {
            observer.update(newTemperature);
        }
    }
}
